package com.we.connect.weconnect.utils;

import com.we.connect.weconnect.model.remind.vo.RemindInfoVo;
import com.we.connect.weconnect.model.system.SysInfo;
import com.we.connect.weconnect.quarte.WeConnectJob;
import org.quartz.*;

public class ScheduleUtils {

    public static void createScheduleJob(Scheduler scheduler, RemindInfoVo remindInfoVo, SysInfo sysInfo) throws Exception {

        JobDetail jobDetail = JobBuilder.newJob(WeConnectJob.class).withIdentity(String.valueOf(remindInfoVo.getTableId())).build();

        // 设置时间
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(remindInfoVo.getTime());
        cronScheduleBuilder = cronScheduleBuilder.withMisfireHandlingInstructionDoNothing();

        CronTrigger time = TriggerBuilder.newTrigger().
                withIdentity(String.valueOf(remindInfoVo.getTableId())).
                withSchedule(cronScheduleBuilder).
                build();

        jobDetail.getJobDataMap().put("remindInfoVo", remindInfoVo);
        jobDetail.getJobDataMap().put("sysInfo", sysInfo);

        scheduler.scheduleJob(jobDetail, time);

    }

}
